home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / daemons / ipServer / ipServer.h < prev    next >
Encoding:
C/C++ Source or Header  |  1991-12-06  |  4.3 KB  |  141 lines

  1. /*
  2.  * ipServer.h --
  3.  *
  4.  *    Global declarations of the Internet protocol server process.
  5.  *
  6.  * Copyright 1987 Regents of the University of California
  7.  * All rights reserved.
  8.  * Permission to use, copy, modify, and distribute this
  9.  * software and its documentation for any purpose and without
  10.  * fee is hereby granted, provided that the above copyright
  11.  * notice appear in all copies.  The University of California
  12.  * makes no representations about the suitability of this
  13.  * software for any purpose.  It is provided "as is" without
  14.  * express or implied warranty.
  15.  *
  16.  * $Header: /sprite/src/daemons/ipServer/RCS/ipServer.h,v 1.7 89/08/15 19:55:32 rab Exp $ SPRITE (Berkeley)
  17.  */
  18.  
  19. #ifndef _IPS_IPSERVER
  20. #define _IPS_IPSERVER
  21.  
  22. #include "sprite.h"
  23. #include "status.h"
  24. #include "stdlib.h"
  25. #include "net.h"
  26. #ifndef KERNEL
  27. /*
  28.  * We can only use the regular C library stdio in the user-level ipServer.
  29.  * The kernel has its own printf routines.
  30.  */
  31. #include <stdio.h>
  32. #else
  33. #define stderr    0
  34. #define stdout 0
  35. typedef int FILE;
  36. #endif
  37.  
  38. /* macros and constants */
  39.  
  40. #define MIN(a, b)    ((a) < (b) ? (a) : (b))
  41. #define MAX(a, b)    ((a) > (b) ? (a) : (b))
  42.  
  43. /*
  44.  * Internal representations of the protocol numbers.
  45.  * The protocol numbers in netInet.h are not contiguous and too spread
  46.  * out to be useful. If you add a protocol here, be sure to update
  47.  * the Sock_Init routine in sockOps.c.
  48.  */
  49. #define RAW_PROTO_INDEX        0
  50. #define UDP_PROTO_INDEX        1
  51. #define TCP_PROTO_INDEX        2
  52. #define MAX_PROTO_INDEX        TCP_PROTO_INDEX
  53.  
  54.  
  55. /* data structures */
  56.  
  57.  
  58. /*
  59.  * The IPS_Packet structure describes the format of a memory buffer that
  60.  * holds an incoming or outgoing packet. Every packet has an network header,
  61.  * an IP header, possibly a header for a higher-level protocol, and data.
  62.  * For an incoming packet, the headers begin at the base address of the
  63.  * buffer. For an outgoing packet, the headers are added "bottom-up" so
  64.  * there might be a gap of unused memory between the base and the network
  65.  * header. The routine that allocates an outgoing packet must reserve enough
  66.  * space to insert all the headers.
  67.  *
  68.  * The network header is not touched by the protocol routines. Only the
  69.  * I/O routine is allowed to manipulate it.
  70.  */
  71.  
  72. typedef struct {
  73.     int            totalLen;    /* Total length (in bytes) of the
  74.                      * buffer. */
  75.     Address        base;        /* Base address returned by Mem_Alloc.
  76.                      * This is the address that is given
  77.                      * to Mem_Free to release the buffer. */
  78.     Address        dbase;        /* Base address of data in buffer. */
  79.     /*
  80.      * The following pointers point to addresses within the buffer that
  81.      * starts at base and ends at (base + totalLen - 1).
  82.      */
  83.  
  84.     union {
  85.     Net_EtherHdr    *etherPtr;    /* Ptr. to the ethernet header. */
  86.     /*
  87.      * Ptrs to headers for other network types go here.
  88.      *   NOTE: If you add a field here, add a corresponding field in
  89.      *         IPS_PacketNetHdr below.
  90.      */
  91.     } net;
  92.  
  93.     int            ipLen;        /* Length in bytes of the IP header. */
  94.     Net_IPHeader    *ipPtr;        /* Ptr to the IP header. */
  95.     int            hdrLen;        /* Length in bytes of the higher-level
  96.                      * protocol header. May be 0. */
  97.     union {                /* Ptr. to the HL protocol header. */
  98.     Net_UDPHeader    *udpPtr;
  99.     Net_TCPHeader    *tcpPtr;
  100.     Net_ICMPHeader    *icmpPtr;
  101.     Address        *hdrPtr;
  102.     } hdr;
  103.     int            dataLen;    /* Length in bytes of the data.
  104.                      * May be 0. */
  105.     Address        data;        /* Ptr to the data. */
  106. } IPS_Packet;
  107.  
  108. /*
  109.  * IPS_ROOM_FOR_HEADERS defines how much space might be used by the
  110.  * protocol headers.  This is used to overallocate space so that the
  111.  * packet data may be left in place during packet formatting.
  112.  */
  113. #define IPS_ROOM_FOR_HEADERS    ( (NET_TCP_MAX_HDR_SIZE + \
  114.                    NET_IP_MAX_HDR_SIZE + \
  115.                    sizeof(IPS_PacketNetHdr) + \
  116.                    sizeof(int)) & ~(sizeof(int) - 1) )
  117. /*
  118.  * This type is used by routines when they need to allocate space in an
  119.  * IPS_Packet for the network header in a network-independent way.
  120.  * Usage: sizeof(IPS_PacketNetHdr);
  121.  */
  122.  
  123. typedef union {
  124.     Net_EtherHdr    ether;        /* Ethernet header. */
  125.     /*
  126.      * Headers for other network types go here.
  127.      *   NOTE: If you add a field here, add a corresponding field in
  128.      *         net union in IPS_Packet above.
  129.      */
  130.  
  131. } IPS_PacketNetHdr;
  132.  
  133. /* procedures and variables */
  134.  
  135. extern Boolean        ips_Debug;
  136.  
  137. extern int        IPS_GetTimeStamp();
  138. extern void        IPS_InitPacket();
  139.  
  140. #endif /* _IPS_IPSERVER */
  141.